/**
 @file sys_usw_wb_nh.h

 @date 2010-01-13

 @version v2.0

 The file defines queue api
*/

#ifndef _SYS_USW_WB_NH_H_
#define _SYS_USW_WB_NH_H_
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"

#include "ctc_const.h"
#include "ctc_macro.h"
#include "ctc_debug.h"
#include "ctc_warmboot.h"
#include "sys_usw_chip.h"

/****************************************************************
*
* Defines and Macros
*
****************************************************************/
/**
 @brief  define l2 FDB entry sync flags
*/
enum sys_wb_appid_nh_subid_e
{
    SYS_WB_APPID_NH_SUBID_MASTER,
    SYS_WB_APPID_NH_SUBID_INFO_COM,
    SYS_WB_APPID_NH_SUBID_MPLS_TUNNEL,
    SYS_WB_APPID_NH_SUBID_ECMP,
    SYS_WB_APPID_NH_SUBID_INFO_MCAST,
    SYS_WB_APPID_NH_SUBID_ARP,
    SYS_WB_APPID_NH_SUBID_VNI,
    SYS_WB_APPID_NH_SUBID_SRH,
    SYS_WB_APPID_NH_SUBID_OL_TUNNEL,
    SYS_WB_APPID_NH_SUBID_APS,
    SYS_WB_APPID_NH_SUBID_FP,
    SYS_WB_APPID_NH_SUBID_ECMP_MEM,
    SYS_WB_APPID_NH_SUBID_MCAST_MEM,
    SYS_WB_APPID_NH_SUBID_MCAST_L3IF,
    SYS_WB_APPID_NH_SUBID_NSH,
    SYS_WB_APPID_NH_SUBID_LOOP_NH,
    SYS_WB_APPID_NH_SUBID_MAX
};
typedef enum sys_wb_appid_nh_subid_e sys_wb_appid_nh_subid_t;

struct sys_wb_nh_ipmc_l3if_s
{
    /*key*/
    uint32  l3if_id;
    uint32  calc_key_len[0];

    /*data*/
    uint32   nh_offset;
    uint32   pon_nh_offset;
};
typedef struct sys_wb_nh_ipmc_l3if_s sys_wb_nh_ipmc_l3if_t;


struct sys_wb_nh_info_special_s
{
    uint16 dest_gport;
    uint16 rsv;
};
typedef struct sys_wb_nh_info_special_s sys_wb_nh_info_special_t;

struct sys_wb_nh_info_rspan_s
{
    uint8 remote_chip;
    uint8 rsv[3];
};
typedef struct sys_wb_nh_info_rspan_s sys_wb_nh_info_rspan_t;

struct sys_wb_nh_info_brguc_s
{
    uint16  dest_gport;
    uint8   nh_sub_type; /*sys_nh_param_brguc_sub_type_t*/
    uint8   flag;
    uint16 dest_logic_port;
     uint16 service_id;
    uint32 l2_edit_ptr;
};
typedef struct sys_wb_nh_info_brguc_s sys_wb_nh_info_brguc_t;

struct sys_wb_nh_info_ipuc_s
{
    uint32 gport;       

    uint32 l3ifid : 13;
    uint32 l2_edit_ptr : 19;

    uint32 flag   : 16;
    uint32 ldp_ext : 16;

    uint32 arp_id : 20;
    uint32 is_8w  : 1;
    uint32 adjust_len : 8;
    uint32 ldp_ext_alloc : 1;
    uint32 rsv : 2;

    /*restore bind info, Notice: bind data should recover from fwd module, eg:ipuc/acl/mpls etc*/
};
typedef struct sys_wb_nh_info_ipuc_s sys_wb_nh_info_ipuc_t;



struct sys_wb_nh_info_mpls_s
{
    uint32   gport;
    
    uint32   adjust_len:8;
    uint32   ttl : 8;
    uint32   l3ifid       : 13;
    uint32   aps_xcon_met: 1;
    uint32   op_code     : 2;    

    uint32   dest_logic_port:16; /*H-vpls*/    
    uint32   inner_l2_ptr:16;
    
    uint32   outer_l2_ptr:16;
    uint32   dsl3edit_offset:16;
    
    uint32   tunnel_id:16;
    uint32   service_id:16;    
    
    uint32  svlan_edit_type : 3;
    uint32  cvlan_edit_type : 3;
    uint32  nh_prop : 2;    
    uint32  ttl_mode  : 2;
    uint32  is_hvpls  : 1;
    uint32  is_loop_nh  : 1;
    uint32  cw_index    :4;   
    uint32  rsv : 16;

    uint32  arp_id:20;
    uint32  rsv1 : 12;
    uint32  met_offset;
};
typedef struct sys_wb_nh_info_mpls_s sys_wb_nh_info_mpls_t;

struct sys_wb_nh_info_wlan_s
{
    uint32  dsl3edit_offset;
    uint32  gport;
    uint8   flag;                /* sys_nh_wlan_tunnel_flag_t */
    uint8   sa_index;
    uint16  dest_vlan_ptr;
    uint32  inner_l2_ptr;
};
typedef struct sys_wb_nh_info_wlan_s sys_wb_nh_info_wlan_t;

struct sys_wb_nh_info_ol_vni_s
{
    uint32 inner_l2_edit_offset :16;
    uint32  svlan_edit_type : 3;
    uint32  cvlan_edit_type : 3;
	uint32  rsv : 10;
};
typedef struct sys_wb_nh_info_ol_vni_s sys_wb_nh_info_ol_vni_t;

struct sys_wb_nh_info_overlay_s
{
    uint32 gport;
    uint32 nhid;
    uint32 dest_logic_port:16;
    uint32 is_ecmp_nh : 1;
    uint32 rsv : 15;
    uint32 ecmp_gid;
};
typedef struct sys_wb_nh_info_overlay_s sys_wb_nh_info_overlay_t;

struct sys_wb_nh_info_ip_tunnel_s
{
    uint32 gport;
    uint32 vn_id;
    uint32 dot1ae_channel;
    uint32 ctc_flag;        /*used for get nh parameter*/
    
    uint32 flag:16; /* sys_nh_ip_tunnel_flag_t */
    uint32 l3ifid:16;

    uint32 dest_vlan_ptr:16;
    uint32 span_id :10;
    uint32 inner_pkt_type : 3;
    uint32 share_type     : 3;
    
    uint32 dest_logic_port:16; /*H-overlay*/
    uint32 dsl3edit_offset:16;
    
    uint32 inner_l2_edit_offset:16;
    uint32 outer_l2_edit_offset:16;

    uint32 sa_index          : 8;
    uint32 adjust_len        : 8;
    uint32 sc_index          : 7;
    uint32 sci_en            : 1;
    uint32 dot1ae_en         : 1;
    uint32 udf_profile_id    : 6;
    uint32 is_12w            : 1;
    
    uint32 arp_id            : 20; 
    uint32 tunnel_type       : 5;    
    uint32 rsv               : 7;    
};
typedef struct sys_wb_nh_info_ip_tunnel_s sys_wb_nh_info_ip_tunnel_t;

struct sys_wb_nh_info_trill_s
{
    uint16 ingress_nickname;
    uint16 egress_nickname;
    uint16 l3ifid;
    uint16 dest_vlan_ptr;
    uint32 gport;
    uint32 dsl3edit_offset;
    uint32 l2_edit_ptr;
};
typedef struct sys_wb_nh_info_trill_s sys_wb_nh_info_trill_t;

struct sys_wb_nh_info_misc_s
{
    uint16 dsl2edit_offset;
    uint16 dsl3edit_offset;

    uint32 gport;
    uint16 next_l3edit_offset;
    uint16 truncated_len;

    uint32 l3ifid            :13;
    uint32 vlan_profile_id  :6;
    uint32 packet_type   : 3;
    uint32 ctag_op       : 3;
    uint32 scos_sl       : 2;
    uint32 stag_op       : 3;
    uint32 svid_sl       : 2;

    uint32 ccos_sl         : 2;
    uint32 is_reflective   : 1;
    uint32 label_num       : 2;
    uint32 cvlan_edit_type :3;
    uint32 svlan_edit_type :3;
    uint32 cvid_sl         :2;
    uint32 is_loop_nh      :1;
    uint32 misc_nh_type    :4;
    uint32 rsv1            :14;

    uint32 flag;
    uint8  l3edit_entry_type;
    uint8  l2edit_entry_type;
    uint8  next_l3edit_entry_type;
    uint8  rsv2;

};
typedef struct sys_wb_nh_info_misc_s sys_wb_nh_info_misc_t;



struct sys_wb_nh_info_com_hdr_s
{
    uint32 dsnh_entry_num : 4;
    uint32 rsv            : 28;
    uint32 nh_entry_flags;      /*sys_nh_info_flag_type_t*/
    uint32 dsfwd_offset:16;
    uint32 dsfwd1_offset:16;
    uint32 dsnh_offset;
};
typedef struct sys_wb_nh_info_com_hdr_s sys_wb_nh_info_com_hdr_t;

struct sys_wb_nh_info_ecmp_mem_s
{
    /*key*/
    uint32  nhid;
    uint16  mem_index;
    uint32  calc_key_len[0];

    /*data*/
    uint32   mem_nh;
    uint8    mem_id;
    uint8    entry_cnt;
};
typedef struct sys_wb_nh_info_ecmp_mem_s sys_wb_nh_info_ecmp_mem_t;

struct sys_wb_nh_info_ecmp_s
{
    /*key*/
    uint32  nh_id;
    uint32  nh_type; /*sys_usw_nh_type_t*/
    uint32  calc_key_len[0];

    /*data*/
    sys_wb_nh_info_com_hdr_t hdr;

    uint16   gport;
    uint16   ecmp_member_base;
    uint16   l3edit_offset_base;
    uint16   l2edit_offset_base;

    uint32   ecmp_cnt      :12;   /*include unresoved nh member*/
    uint32   valid_cnt     :12;  /*valid member*/
    uint32   ant_flow_base :8;

    uint32   mem_num       :13;  /*max member num in group*/
    uint32   ecmp_group_id :12;
    uint32   type          :3;        /*ctc_nh_ecmp_type_t*/
    uint32   hecmp_en      :1;
    uint32   ant_flow_en   :1;
    uint32   failover_en   :1;
    uint32   random_rr_en  :1;    

    uint32 rpf_id           :9;
    uint32 stats_valid      :1;
    uint32 mem_is_tunnel    :1;
    uint32 tunnel_is_ldp    :1;
    uint32 srh_replace_ipda :1;
    uint32 rsv              :19;
};
typedef struct sys_wb_nh_info_ecmp_s sys_wb_nh_info_ecmp_t;

struct sys_wb_nh_info_srv6_s
{
    /*key*/
    uint32  nh_id;
    uint32  nh_type; /*sys_usw_nh_type_t*/
    uint32  calc_key_len[0];

    /*data*/
    uint16  flag;           /* sys_nh_srv6_flag_t */
    uint16 dest_logic_port;

    uint32 srh_id;
    uint32 gport;
    uint16 dsl3edit_offset;
    uint16 outer_l2_edit_offset;

    uint32  l3ifid :13;
    uint32  svlan_edit_type : 3;
    uint32  cvlan_edit_type : 3;
    uint32  aps_xcon_met    : 1;
    uint32  replace_last    : 1;
    uint16  rsv             : 3;
    uint32  ipsa_index      : 4;
    uint32  srv6_type       : 4;
    uint32  ecmp_if_id      : 13;
    uint32  rsv1            : 19;
    uint32  fp_id;
    uint32  met_offset;

};
typedef struct sys_wb_nh_info_srv6_s sys_wb_nh_info_srv6_t;

struct sys_wb_nh_info_aps_s
{
    /*key*/
    uint32  nh_id;
    uint32  nh_type; /*sys_usw_nh_type_t*/
    uint32  calc_key_len[0];

    /*data*/
    sys_wb_nh_info_com_hdr_t hdr;
    uint32 w_nexthop_id;
    uint32 p_nexthop_id;
    uint16 aps_group_id;
    uint8  assign_port : 1;
    uint8  arp_num     : 2;
    uint8  aps_xcon_met : 1;
    uint8  rsv:4;
};
typedef struct sys_wb_nh_info_aps_s sys_wb_nh_info_aps_t;

struct sys_wb_nh_arp_s
{
    /*key*/
    uint32  arp_id:20;
    uint32  rsv:12;
    uint32  calc_key_len[0];

    /*data*/
    uint16  output_vid:12;
    uint16  l3if_type :3; /**< the type of l3interface , CTC_L3IF_TYPE_XXX */
    uint16  output_vlan_is_svlan:1;
    mac_addr_t mac_da;

    uint8  flag;
    uint8  ldp_mac_profile;
    uint16 offset_dyn;    /*dynamic l2 edit for ipuc vlan edit*/

    uint32 destmap_profile:12;
    uint32 output_cvid    : 12;
    uint32 is_8w          : 1;
    uint32 rsv1           : 7;

    uint32 gport;
    uint16 l3if_id;
    uint16 offset;          /*static outer l2 edit for mpls/tunnel vlan & mac edit*/
    uint32 dsfwd_offset;
};
typedef struct sys_wb_nh_arp_s sys_wb_nh_arp_t;

struct sys_wb_nh_vni_fid_s
{
    /*key*/
    uint32 vn_id;
    uint32  calc_key_len[0];

    /*data*/
    uint16 fid;
    uint16 ref_cnt;
};
typedef struct sys_wb_nh_vni_fid_s sys_wb_nh_vni_fid_t;

struct sys_wb_nh_srh_s
{
    /*key*/
    uint32 srh_id;
    uint32  calc_key_len[0];

    /*data*/
    uint32 p_srh_id;
    
    uint32 l3edit_ptr:16;
    uint32 flag:16;                      /* sys_nh_srh_flag_t */

    uint32 arp_id:20;
    uint32 segment_left :3;
    uint32 num      :3;
    uint32 is_reduce:1;
    uint32 alloc_en :1;    
    uint32 rsv      :4;
    uint32 ldp      :16;
    uint32 rsv1     :16;
};
typedef struct sys_wb_nh_srh_s sys_wb_nh_srh_t;

struct sys_wb_nh_ol_tunnel_s
{
    /*key*/
    uint32 logic_port;
    uint32  calc_key_len[0];

    /*data*/
    uint32 dot1ae_channel;
    uint32 ul_nhid;
    
    uint32 dsl3edit_offset:16;
    uint32  flag:16;/* sys_nh_ip_tunnel_flag_t */    
    
    uint32 ecmp_if_id :16;
    uint32  sa_index:8;
    uint32  sc_index:8;

    uint32 arp_id      :20;
    uint32 dot1ae_en   :1;
    uint32 sci_en      :1;
    uint32 is_4x       :1;
    uint32 tunnel_type :2;
    uint32 ul_nh_en    :1;
    uint32 rsv         :6;
    uint32 gport;
};
typedef struct sys_wb_nh_ol_tunnel_s sys_wb_nh_ol_tunnel_t;

struct sys_wb_nh_nsh_s
{
    uint16 nsh_id;
    uint32 calc_key_len[0];

    uint16 edit_offset;
    uint8 nsh_ch_len;
    uint8 rsv;
};
typedef struct sys_wb_nh_nsh_s sys_wb_nh_nsh_t;

#define SYS_NH_APS_M 2
#define SYS_MPLS_NH_MAX_TUNNEL_LABEL_NUM   12
struct sys_wb_nh_mpls_sr_s
{
    uint32 dsnh_offset;
    uint32 pw_offset  : 16;
    uint32 lsp_offset : 16;
    uint32 spme_offset: 16;
    uint32 l2edit_offset : 16;
};
typedef struct sys_wb_nh_mpls_sr_s sys_wb_nh_mpls_sr_t;
struct sys_wb_nh_mpls_tunnel_s
{
    /*key*/
    uint16  tunnel_id;
    uint32 calc_key_len[0];

    /*data*/
    sys_wb_nh_mpls_sr_t sr[SYS_MPLS_NH_MAX_TUNNEL_LABEL_NUM];
    uint32  gport; /*if SYS_NH_MPLS_TUNNEL_FLAG_APS is set, it is aps group id*/
    uint32  loop_nhid;
    
    uint32  l3ifid:16;
    uint32   label_num:8;
    uint32   sr_loop_num:8;    

    uint32  l2edit_offset:16;
    uint32  spme_offset:16;  
    
    uint32  lsp_offset:16;
    uint32  lsp_ttl:8;
    uint32  spme_ttl:8;

    uint32  flag:16; /*sys_nh_dsmet_flag_t,SYS_NH_MPLS_TUNNEL_FLAG_XX*/
    uint32  rsv:16;
    
    uint32  arp_id:20;
    uint32  rsv1:12;    
};
typedef struct sys_wb_nh_mpls_tunnel_s  sys_wb_nh_mpls_tunnel_t;


struct sys_wb_nh_info_mcast_mem_s
{
   /*key*/
    uint32   basic_met_offset;
    uint32   dsmet_offset;
    uint32   calc_key_len[0];

    /*data*/
    uint32   next_dsmet_offset     :20;
    uint16   vid                   :12;
    uint32   flag; /*sys_nh_dsmet_flag_t,SYS_NH_DSMET_FLAG_XX*/

    uint32   dsnh_offset;
    uint32   ref_nhid;

    uint16   replicate_num; /*replicate_num for IPMC; port num of l2mc port bitmap*/
    uint16   cvid                  :12;
    uint16   free_dsnh_offset_cnt  :4;

    uint8    member_type           :4;
    uint8    port_type             :4;
    uint8    entry_type;
    uint16   ucastid;

    uint16   fid;
    uint16   logic_port;
    uint32   mcast_nhid;
};
typedef struct sys_wb_nh_info_mcast_mem_s sys_wb_nh_info_mcast_mem_t;

struct sys_wb_nh_info_mcast_s
{
   /*key*/
    uint32   basic_met_offset;
    uint32   calc_key_len[0];

    /*data*/
    sys_wb_nh_info_com_hdr_t hdr;
    uint32   nh_id;
    uint16   physical_replication_num;
    uint8    pp_bmp;
    uint8    rsv;
    uint32   profile_met_offset :20;
    uint8    mcast_flag;
    uint8    rsv1               :4;
    uint32   profile_nh_id;
};
typedef struct sys_wb_nh_info_mcast_s sys_wb_nh_info_mcast_t;

struct sys_wb_nh_info_com_s
{
    /*key*/
    uint32  nh_id;
    uint32  nh_type; /*sys_usw_nh_type_t*/
    uint32  calc_key_len[0];

    /*data*/
    sys_wb_nh_info_com_hdr_t hdr;
    union {
        sys_wb_nh_info_misc_t    misc;   /*36B*/
        sys_wb_nh_info_trill_t   trill;  /*20B*/
        sys_wb_nh_info_ip_tunnel_t ip_tunnel;  /* 48B */
        sys_wb_nh_info_mpls_t    mpls;  /*48B*/
        sys_wb_nh_info_special_t spec;  /*4B*/
        sys_wb_nh_info_rspan_t   rspan; /*4B*/
        sys_wb_nh_info_brguc_t   brguc; /*20B*/
        sys_wb_nh_info_ipuc_t    ipuc;  /*32B*/
        sys_wb_nh_info_wlan_t    wlan;  /*16B*/
        sys_wb_nh_info_ol_vni_t    ol_vni; /*4B*/
        sys_wb_nh_info_overlay_t    overlay; /*12B*/
        sys_wb_nh_info_srv6_t    srv6; /*44B*/
    }info;
};
typedef struct sys_wb_nh_info_com_s sys_wb_nh_info_com_t;

struct sys_wb_nh_loop_nh_s
{
    /*key*/
    uint32 nhid;   /*nhid and edit_ptr are 1:1*/
    uint32  calc_key_len[0];

    /*data*/
    uint32 edit_ptr;
    uint32 is_l2edit:1;
    uint32 lb_with_ldp:1;
    uint32 rsv:14;
    uint32 ref_cnt:16;
};
typedef struct sys_wb_nh_loop_nh_s sys_wb_nh_loop_nh_t;


struct sys_wb_nh_ipsa_v4_node_s
{
    uint32  count;
    ip_addr_t ipv4;
};
typedef struct sys_wb_nh_ipsa_v4_node_s sys_wb_nh_ipsa_v4_node_t;

struct sys_wb_nh_ipsa_v6_node_s
{
    uint32  count;
    ipv6_addr_t ipv6;
};
typedef struct sys_wb_nh_ipsa_v6_node_s sys_wb_nh_ipsa_v6_node_t;

#define SYS_NH_CW_NUM 16
#define SYS_SPEC_L3IF_NUM               8191
#define SYS_NH_PON_MC_DSNH_NUM 2
struct sys_wb_nh_master_s
{
    /*key*/
    uint32 lchip;   /*lchip*/
    uint32 calc_key_len[0];

    /**data */
    uint32    version;
    uint32     max_external_nhid;
    uint16     max_tunnel_id;
    uint16     ecmp_if_resolved_l2edit;
    uint16     reflective_resolved_dsfwd_offset;
    uint16     cw_ref_cnt[SYS_NH_CW_NUM];
    uint16     max_ecmp;               /**<  the maximum ECMP paths allowed for a route */
    uint16     cur_ecmp_cnt;
    uint32     udf_profile_bitmap;       /* for restore udf used profile */
    uint16     udf_ether_type[8];        /* for restore udf ether type for each udf profile */
    uint32     efd_nh_id;                /* for restore efd redirect nexthop id*/
    uint32     rsv_nh_ptr;               /* reserve nexthop ptr for ipuc loop in replace mode */
    uint16    outer_l2_ptr;/*TMM, for misc nexthop mpls replace*/
    uint16    outer_l2_ptr_ref;/*TMM*/
    uint16     max_ecmp_group_num;
    uint16     rsv_l2edit_ptr;           /* reserve l2edit ptr for ip bfd in replace mode */
    uint32     rsv_iloop_nh;
    uint32     rsv_l3edit_for_nsh;
    uint32     srv6_resolved_l2edit;
    uint16     rsv_l3edit_for_igs_edit;
    uint16     rsv_xedit_for_igs_edit;
    uint16      bpe_mc_en             :1;
    uint16      reflective_brg_en     :1;
    uint16      ipmc_logic_replication:1;
    uint16      pkt_nh_edit_mode      :2;
    uint16      rspan_nh_in_use       :1;
    uint16      no_dsfwd              :1;
    uint16      vxlan_mode            :2;
	uint16      rsv            :7;
    uint8      hecmp_mem_num;
    uint16     gem_port_edit_num;
    uint16     gem_port_edit_base;
    uint16     max_srh_id;
    uint32     pon_mc_dsnh[SYS_NH_PON_MC_DSNH_NUM];
};
typedef struct sys_wb_nh_master_s sys_wb_nh_master_t;


struct sys_wb_nh_brguc_node_s
{
    /*key*/
    uint32 gport;   /*lchip*/
    uint32 calc_key_len[0];

    /*data*/
    uint32 nhid_brguc;
    uint32 nhid_bypass;
};
typedef struct sys_wb_nh_brguc_node_s sys_wb_nh_brguc_node_t;

struct sys_wb_nh_fp_s
{
    /*key*/
    uint32 fp_id;
    uint32 calc_key_len[0];

    /*data*/
    uint32 l3_edit_ptr;
    uint32 pair_edit_ptr;
    uint8  alloc_en:1;
    uint8  use_outer_edit:1;
    uint8  fp2:1;
    uint8 ext_mode:2;
    uint8 is_internal:1;
    uint8 rsv0:3;
    uint8 rsv[3];
    uint16 alu_prof_id;
    uint16 data_prof_id;
    uint16 l3chksum_prof_id;
    uint16 l4chksum_prof_id;
};
typedef struct sys_wb_nh_fp_s sys_wb_nh_fp_t;

#ifdef __cplusplus
}
#endif

#endif
